package com.zpself.module.面试草搞.老虎与羊;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import java.util.Scanner;

/**
 * @author By ZengPeng
 * @Description
 * @date in  2020/9/14 17:56
 * @Modified By
 */
public class StartGame {

    public static void main(String[] args) {
        //初始化10个房间
        List<Room> rooms = new ArrayList<>(10);
        Room currentRoom = null;
        for (int i = 0; i < 10; i++) {
            if(new Random().nextInt(2)==1)
                currentRoom = new Room(AnimalType.tiger,200);
            else
                currentRoom = new Room(AnimalType.sheep,100);
            rooms.add(currentRoom);
        }
        Scanner s = new Scanner(System.in);
        String currentInput="";
        long startTime = System.currentTimeMillis();
        //判断游戏是否结束，游戏时间3分钟
        while (System.currentTimeMillis() - startTime <= 1 * 60 * 1000) {
            //循环让用户输入，根据输入操作room对象
            //随机给出房间
            Room targetRoom = rooms.get(new Random().nextInt(rooms.size()));
            System.out.println("请选择敲门【Q】 或者喂食【W】");
            currentInput =  s.next();
            if(currentInput .equalsIgnoreCase("Q")){
               //进行敲门操作
                knockDoor(targetRoom );
            }else if(currentInput .equalsIgnoreCase("W")){
                //进行喂食操作
                feed(targetRoom,s);
            }else {
                System.out.println("对不起你输入不符合规范！");
            }
        }

    }

    private static void feed(Room targetRoom, Scanner s) {

        System.out.println("请选择 meat  或 grass ");
        String currentInput=s.next();
        boolean isOk;
        if(currentInput .equalsIgnoreCase("meat")){
            isOk = targetRoom.getType().equals(AnimalType.tiger);
        }else if(currentInput .equalsIgnoreCase("grass")){
            isOk = targetRoom.getType().equals(AnimalType.sheep);
        }else {
            System.out.println("对不起你输入不符合规范！");
            return;
        }
        //根据判断打印结果
        if(isOk){
            targetRoom.setWeight(targetRoom.getWeight()+10);
            System.out.println("输入正确！ 房间里的是:"+targetRoom.getType()+",体重+10");
        }
        else{
            targetRoom.setWeight(targetRoom.getWeight()-10);
            System.out.println("输入错误！房间里的是:"+targetRoom.getType()+",体重-10");
        }

    }

    private static void knockDoor(Room targetRoom) {
        if (targetRoom.getType().equals(AnimalType.sheep))
            System.out.println("mie~~");
        else
            System.out.println("Wow !!");
    }
}
